//
//  NearTableViewCell.m
//  wtshoppingcite
//
//  Created by TW on 14-10-17.
//  Copyright (c) 2014年 TW. All rights reserved.
//

#import "NearTableViewCell.h"
#import "Macro.h"
#import "UIImage+ImageName.h"
#import "AttrPriceLabel.h"

@implementation NearTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews{
    
    _iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 100, 80)];
    [self.contentView addSubview:_iconImageView];

    _titleLable = [[UILabel alloc]initWithFrame:CGRectMake(_iconImageView.right + 10, _iconImageView.top, kWidth-_iconImageView.width - 20, 20)];
    [self.contentView addSubview:_titleLable];
    _titleLable.font = [UIFont systemFontOfSize:15.0f];
    _titleLable.backgroundColor = [UIColor clearColor];
    _titleLable.numberOfLines = 0;
    _titleLable.textColor = MAIN_BLACK_COLOR;
    
    _subTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(_titleLable.left, _titleLable.bottom+2,kWidth-_iconImageView.width - 20, 20)];
    [self.contentView addSubview:_subTitleLabel];
    _subTitleLabel.font = [UIFont systemFontOfSize:13.0f];
    _subTitleLabel.backgroundColor = [UIColor clearColor];
    _subTitleLabel.numberOfLines = 2;
    _subTitleLabel.textColor = UIColorFromRGB(0x9fa0a0);
    
    
    _iconImage = [[UIImageView alloc]initWithFrame:CGRectMake(_iconImageView.right + 10, _subTitleLabel.bottom + 25, 8, 8)];
    [self.contentView addSubview:_iconImage];
    
    
    _sPriceLable = [[UILabel alloc] initWithFrame:CGRectMake(_iconImage.right, _subTitleLabel.bottom+5, 45, 45)];
    [self.contentView addSubview:_sPriceLable];
     _sPriceLable.font = [UIFont systemFontOfSize:16.0f];
    _sPriceLable.textAlignment = NSTextAlignmentLeft;
    _sPriceLable.backgroundColor = [UIColor clearColor];
    _sPriceLable.textColor = MAIN_BLUE_COLOR;
    
    
    _seprateLable = [[AttrPriceLabel alloc] initWithFrame:CGRectMake(_sPriceLable.right -5, _sPriceLable.top, 60, 20)];
    _seprateLable.bottom = _sPriceLable.bottom -10;
     _seprateLable.font = [UIFont systemFontOfSize:12.0f];
     _seprateLable.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_seprateLable];
    
    
    UILabel *sNumLable = [[UILabel alloc]initWithFrame:CGRectMake(kWidth - 60, _iconImage.top -10, 25, 30)];
    sNumLable.text = @"已售";
    sNumLable.font = [UIFont systemFontOfSize:12.0f];
    [self.contentView addSubview:sNumLable];
    sNumLable.backgroundColor = [UIColor clearColor];
    sNumLable.textColor = UIColorFromRGB(0x9fa0a0);
    
    _sNum = [[UILabel alloc]initWithFrame:CGRectMake(sNumLable.right, sNumLable.top, 30, 30)];
    [self.contentView addSubview:_sNum];
    _sNum.font = [UIFont systemFontOfSize:12.0f];
    _sNum.backgroundColor = [UIColor clearColor];
    _sNum.textColor = UIColorFromRGB(0x9fa0a0);
}

-(void)setShoppingModel:(ShoppingModel *)shoppingModel{
    
    if (_shoppingModel != shoppingModel) {
        _shoppingModel = shoppingModel;
        
        //_iconImageView.image =[UIImage imageNamed:self.shoppingModel.sPic];
        
         [_iconImageView  setImageWithURL:[NSURL URLWithString:self.shoppingModel.sPic] placeholderImage:[UIImage imageNamed:@"all_defalutImage"]];
        _iconImage.image = [UIImage imageNamed:@"money_code"];
        _titleLable.text = self.shoppingModel.title;
        _subTitleLabel.text = self.shoppingModel.subTitle;
        _sPriceLable.text = CHECK_IS_NULL(self.shoppingModel.nPrice);
        if(_sPriceLable.text.length == 0){
            _iconImage.image = nil;
        }
        _sNum.text = self.shoppingModel.saledCount;
        
        //_subTitleLabel.height = 40;
        
        CGSize size = [shoppingModel.nPrice  getSizeOfStringFontSize:14 constroSize:CGSizeMake(50, MAXFLOAT)];
        _seprateLable.width = size.width;
        [_seprateLable setPriceType:2 text:shoppingModel.oPrice];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
